/*
 * Copyright 2011 Ed Clark
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package meander

import net.miginfocom.swing.MigLayout
import javax.swing.border.EtchedBorder
import javax.swing.DefaultListCellRenderer


dialog( title: 'Meander Event Row Editor', id: "tableEditDialog",
        modal: false, pack: true, locationByPlatform: true) {
    panel( id:'teDlg', layout: new MigLayout(), border: new EtchedBorder()) {
        button( 'Insert',
                id: 'Insert',
                actionPerformed: {
                    def currRow = model.selectedRow
                    if ( terpCB.selectedItem == 'before') {
                        controller.addrow( model.selectedRow-1, tercCB.selectedItem, true)
                        model.selectedRow = currRow + tercCB.selectedItem
                    } else {
                        controller.addrow( model.selectedRow, tercCB.selectedItem, false)
                    }
                })
        def lcr = new DefaultListCellRenderer()
        lcr.horizontalAlignment = DefaultListCellRenderer.RIGHT
        comboBox( id: 'tercCB', items: ( 1 .. 50), renderer: lcr)
        label( text: bind( 'selectedItem', source: tercCB, converter: { (it > 1) ? ' rows ' : ' row '}))
        comboBox( id: 'terpCB', items: ['before', 'after'])
        label( text: bind( 'selectedRow', source: model, converter: { " row ${it+1}" }),
               constraints: 'wrap, width 65')
        button( 'Delete',
                id: 'Delete',
                actionPerformed: { controller.deleteCurrentRow() })
        label( text: bind( 'selectedRow', source: model, converter: { " row ${it+1}" }),
               constraints: 'width 65')
    }
}
